﻿using TrueSync;
using UnityEngine;

namespace HEFramework
{
    public static class SkillRangeComponentSystem
    {
        [EntitySystem]
        public class SkillRangeComponentAwakeSystem : AwakeSystem<SkillRangeComponent>
        {
            protected override void Awake(SkillRangeComponent _self)
            {
            }
        }

        public static int Ready(this SkillRangeComponent _self, int _id, TSVector _p1, TSVector _p2, bool _isActive)
        {
            if (_isActive)
            {
                var dc = _self.GetSceneChild<DataTableComponent>();
                if (dc == null)
                {
                    return (int)eSkillErrorCode.System;
                }

                var sData = dc.LoadDataTable<DRSkill>().GetData(_id);
                FP dis = TSVector.Distance(_p1, _p2);
                if (dis > Formula.LG(sData.ARange))
                {
                    return (int)eSkillErrorCode.Lack_RAG;
                }
            }

            return (int)eSkillErrorCode.None;
        }
    }
}